<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__CSS__/x-admin.css" media="all">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>权限规则</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
    <button class="layui-btn layui-btn-danger add"><i class="layui-icon">&#xe640;</i>新增</button>
    <table class="layui-table" id="auth" lay-filter="admin_auth">
    </table>

    <div id="page"></div>
</div>
<script src="__LIB__/layui/layui.js" charset="utf-8"></script>
<script src="__JS__/x-layui.js" charset="utf-8"></script>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看下级</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['element', 'laypage', 'layer', 'form', 'table'], function () {
        $ = layui.jquery;//jquery
        var lement = layui.element;//面包导航
        var laypage = layui.laypage;//分页
        var layer = layui.layer;//弹出层
        var form = layui.form;
        var table=layui.table;

        //监听提交
        form.on('submit(add)', function (data) {
            layer.load(2);
            $.post('{:url("admin/admin.auth/add")}', data.field, function (response) {
                layer.msg(response.msg, {icon: 3});
                layer.closeAll('loading');
                if (response.code = 0) {

                }
            });
            return false;
        });


        $(document).on('click', '.add', function (e) {
            x_admin_show('新增权限', "{:url('admin/admin.auth/add')}", 800, 600);
        });

        table.render({
            elem: "#auth",
            page: true,
            url: '{:url("admin.auth/index")}',
            height: 600,
            cols: [[
                {field: 'id', title: '编号'},
                {field: 'icon', title: "显示图标"},
                {field: 'url', title: "访问地址"},
                {field: 'is_menu', title: "菜单"},
                {field: 'sorted', title: "权重"},
                {title: '操作', toolbar: "#bar", width: 200}
            ]]
        });
        table.on('tool(admin_auth)',function(obj){
            var data=obj.data;
            switch (obj.event) {
                case 'detail':
                    layer.msg('to do');
                    break;
                case 'del':
                    del_row(data.id);
                    break;
                case 'edit':
                    edit_row(data.id);
                    break;
            }
        });
    });

    function edit_row(id){
        x_admin_show("修改","{:url('admin.auth/edit')}"+"?"+$.param({id:id}));
    }
    function del_row(id){
        layer.confirm('确定删除?',function(index){
            $.post("{:url('admin.admin/del')}",{id:id},function (repsonse) {
                layer.msg(response.msg);
                if(repsonse.code==1){
                    layer.close(index);
                }
            })
        })
    }
</script>
</body>
</html>